package com.four.hospital.controller;

import com.four.common.utils.R;
import com.four.hospital.entity.Record;
import com.four.hospital.service.RecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author:luojie
 * @Date: 2022/01/05/18:39
 * @Description
 */
@RestController
@RequestMapping("hospital/record")
public class RecordController {

    @Autowired
    private RecordService recordService;

    /**
     * 记录表根据患者id回显数据
     *
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    public Record findById(@PathVariable("id") Long id) {

        return recordService.findById(id);
    }

    /**
     * 支付
     *
     * @param record
     * @param docId
     * @param userId
     * @return
     */
    @PostMapping("/pay/{docId}/{userId}")
    public R pay(@RequestBody Record record,
                 @PathVariable("docId") Integer docId,
                 @PathVariable("userId") Integer userId) {
        recordService.pay(record, docId, userId);
        return R.ok("支付成功");
    }

    /**
     * 诊断记录
     * @return
     */
    @GetMapping("/recordList/{userToken}")
    public R recordList(@PathVariable("userToken")String userToken) {

        return recordService.recordList(userToken);
    }
}
